{include file="public/head"/}
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-card-header">管理员列表</div>
        <div class="layui-card-body">
            <div class="clt-auth-btns" style="margin-bottom: 10px;">

            </div>
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script type="text/html" id="open">
    {{# if(d.id==1){ }}
    <input type="checkbox" disabled name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" checked>
    {{# }else{ }}
    <input type="checkbox" name="status" {if ADMIN_ID neq 1}disabled{/if} value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.status == 1 ? 'checked' : '' }}>
    {{# } }}
</script>
<script type="text/html" id="action">
    <button class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>
    {{# if(d.id==1){ }}
    <button disabled class="layui-btn layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</button>
    {{# }else{ }}
    {if ADMIN_ID eq 1}
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
    {/if}
    {{# } }}
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加管理员</button>
    </div>
</script>
<script>
    layui.config({
        base: '__LAYDMIN__',
        {if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','admin','table', 'util','form'], function (exports) {
    var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element,form = layui.form;
	var tableLoadDiv = window.top.layer.load(0,{shade:[0.15, '#000']}); //加载层,table.render完成时需要关闭
    //全部数据
    tableIn = table.render({
        elem: '#list',
        url: '{:url(SYS_PATH."/authAdmin/index")}',
        method: 'post',
        page:'true',
        toolbar: '#toolbarDemo',
        title:'管理员列表',
        cols: [[
            {type: "checkbox", fixed: true}
            ,{field:'u_name', title: '用户名', width:150,fixed: true}
            ,{field:'email', title: '邮箱', width:200}
            ,{field:'title', title: '用户组', width:200}
            ,{field:'tel',title: '电话', width:150, hide:true,}
            ,{field:'ip', title: '最后登录IP',width:150}
            ,{field:'status', title: '状态',width:150,toolbar: "#open"}
            ,{width:160, align:'center', toolbar: "#action"}
        ]],
		done:function (res) {   //返回数据执行回调函数
						window.top.layer.close(tableLoadDiv);    //返回数据关闭loading
		}		
    });

    //改变管理员状态
    form.on('switch(open)', function(obj){
        var id = this.value;
        var status = obj.elem.checked===true?1:0;
        admin.req({
            url: '{:url(SYS_PATH."/authAdmin/doStatus")}'
            ,data: {'id':id,'status':status}
            ,type:'post'
            , success: function (res) {
                if(res.code>0){
                    if(obj.elem.checked==true){
                        $(obj.elem).prop('checked',false);
                    }else{
                        $(obj.elem).prop('checked',true);
                    }
                    form.render();
                }else{
                    window.top.layer.msg(res.msg,{time:800,icon:1,shade:[0.5,'#000000']});
                }
            }
        });
    });
	
    //监听工具条
    table.on('tool(list)', function(obj){
        var data = obj.data;
        var id = data.id;
        if(obj.event === 'del'){
			var uri="{:url(SYS_PATH.'/authAdmin/doDelete')}"
			layui.doDelete(uri,"确定要删除吗？",id,obj);//单个删除接口			
			
        } else if(obj.event === 'edit'){
			layui.layerOpen("{:url(SYS_PATH.'/authAdmin/edit')}?id="+id);
        }
    });

    //头工具栏事件
    table.on('toolbar(list)', function(obj){
        switch(obj.event){
            case 'add':
				layui.layerOpen("{:url(SYS_PATH.'/authAdmin/add')}");
                break;
        }
    });

});
	
</script>
</body>
</html>